<?php
namespace app\api\controller;
use think\facade\View;
use think\facade\Db;
use think\facade\Request;

class InfoView extends Base{
    public function __construct(\think\App $app)
    {
        parent::__construct($app);
    }
    public function index()
    {
        $catid=Request::param("catid",0,"intval");
        $id=Request::param("id",0,"intval");
        if(!$catid||!$id){
            $this->error("缺少catid或者id参数");
        }
        $cat=Db::table(config('database.connections.mysql.prefix')."cat")
            ->alias('zb')
            ->join('cat_data fb','zb.catid=fb.catid')
            ->find($catid);
        if(!$cat){
            $this->error("栏目信息不存在！");
        }
        $r=Db::table(config('database.connections.mysql.prefix')."cms_".$cat['table_name'])
            ->alias('zb')
            ->join("cms_".$cat['table_name'].'_data fb','zb.id=fb.id')
            ->find($id);
        if(!$r){
            $this->error("信息不存在！");
        }
        $r['cat']=$cat;
        $this->success($r);
    }

}
